from types import SimpleNamespace

import win32gui

app_name = "手机反恐特别行动"

def enum_windows_callback(hwnd, window_list):
    if win32gui.IsWindowVisible(hwnd):
        window_text = win32gui.GetWindowText(hwnd)
        class_name = win32gui.GetClassName(hwnd)
        rect = win32gui.GetWindowRect(hwnd)
        if window_text:
            window_list.append((hwnd, window_text, class_name, rect))
    return True

def get_all_windows():
    windows = []
    win32gui.EnumWindows(enum_windows_callback, windows)
    return windows

class WindowInfo:
    @staticmethod
    def getGamePoint():
        all_windows = get_all_windows()
        for hwnd, title, class_name, rect in all_windows:
            if title == app_name:
                print(f"Window Handle: {hwnd}, Title: {title}, Class Name: {class_name}, Rect: {rect}")
                left, top, right, bottom = rect
                width = right - left
                height = bottom - top

                point = SimpleNamespace()

                point.left = left
                point.top = top
                point.right = right
                point.bottom = bottom
                point.width = width
                point.height = height
                point.hwnd = hwnd

                return point

if __name__ == "__main__":
    point = WindowInfo.getGamePoint()
    print(point)